#include <dbg.h>

#include <cassert>
#include <unordered_set>

using namespace std;

class Solution {
public:
    long long countOfSubstrings(string word, int k) {
        return countOfSubstring(word, k) - countOfSubstring(word, k + 1);
    }

private:
    unordered_set<char> vowelsSet = {'a', 'e', 'i', 'o', 'u'};

    long long countOfSubstring(string& word, int k) {
        long long res = 0;

        unordered_map<char, int> cntVowels;  // 存储每个元音的计数
        int cntConsonants = 0;               // 辅音字符计数

        int left = 0;
        for (char c : word) {
            if (vowelsSet.count(c)) {  // 元音字符
                ++cntVowels[c];
            } else {  // 辅音字符
                ++cntConsonants;
            }

            while (cntVowels.size() >= 5 && cntConsonants >= k) {
                char out = word[left];
                if (vowelsSet.count(out)) {  // 元音字符
                    --cntVowels[out];
                    if (cntVowels[out] == 0) {  // 移除计数为0的元音字符
                        cntVowels.erase(out);
                    }
                } else {  // 辅音字符
                    --cntConsonants;
                }
                ++left;
            }
            res += left;
        }
        return res;
    }
};

int main() {
    Solution s;

    assert(s.countOfSubstrings("aeioqq", 1) == 0);
    assert(s.countOfSubstrings("aeiou", 0) == 1);
    assert(s.countOfSubstrings("ieaouqqieaouqq", 1) == 3);

    return 0;
}